﻿using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using System.Text.RegularExpressions;


public class NarrowPassage2Easy
{
    public static List<List<T>> GeneratePermutations<T>(List<T> items)
    {
        T[] current_permutation = new T[items.Count];
        bool[] in_selection = new bool[items.Count];
        List<List<T>> results = new List<List<T>>();
        PermuteItems<T>(items, in_selection,
        current_permutation, results, 0);
        return results;
    }

    public static void PermuteItems<T>(List<T> items, bool[] in_selection,
    T[] current_permutation, List<List<T>> results,
    int next_position)
    {
        if (next_position == items.Count)
        {
            results.Add(current_permutation.ToList());
        }
        else
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (!in_selection[i])
                {
                    in_selection[i] = true;
                    current_permutation[next_position] = items[i];
                    PermuteItems<T>(items, in_selection,
                    current_permutation, results,
                    next_position + 1);
                    in_selection[i] = false;
                }
            }
        }
    }

    class ii
    {
        public int i1, i2;
    }
    public int count(int[] size, int maxSizeSum)
    {
        List<ii> overPos1 = new List<ii>();
        for (int i = 0; i < size.Length; i++)
        {
            for (int j = i + 1; j < size.Length; j++)
            {
                if (size[i] + size[j] > maxSizeSum) overPos1.Add(new ii { i1 = i, i2 = j });
            }
        }

        var allcase = GeneratePermutations<int>(Enumerable.Range(0, size.Length).ToList());

        int sum = 0;
        foreach (var acase in allcase)
        {
            bool ok = true;
            foreach (var posii in overPos1)
            {
                int seq = 0;
                foreach (int pos in acase)
                {
                    if (pos == posii.i1 && seq == 0) seq = 1;
                    else if (pos == posii.i2 && seq == 1) seq = 2;
                }
                if (seq != 2)
                {
                    ok = false;
                    break;
                }
            }
            if (ok)
            {
                sum++;
            }
        }
        return sum;
    }
}

class Program
{
    public static void Main(string[] args)
    {
        List<string> result = new List<string>();
        var ret1 = new NarrowPassage2Easy().count(new int[] { 1, 2, 3 }, 3);
        var ret2 = new NarrowPassage2Easy().count(new int[] { 1, 2, 3 }, 1000);
        var ret3 = new NarrowPassage2Easy().count(new int[] { 1, 2, 3 }, 4);
        var ret4 = new NarrowPassage2Easy().count(new int[] { 1, 1, 1, 1, 1, 1 }, 2);
        var ret5 = new NarrowPassage2Easy().count(new int[] { 2, 4, 6, 1, 3, 5 }, 8);
        var ret6 = new NarrowPassage2Easy().count(new int[] { 1000 }, 1000);
      
    }
}
